<?php

namespace App\Repository;
use App\Model\GroupsModel;

/**
 * 用户群组数据仓储数据类
 *
 * @author WangBin
 */
class GroupsRepo extends BaseRepo
{
    /**
     * 保存用户群组
     *
     * @param array $data
     * @param int $userId
     * @return \Hyperf\Utils\HigherOrderCollectionProxy|\Hyperf\Utils\HigherOrderTapProxy|int|mixed|void
     */
    public function save(array $data, int $userId = 0)
    {
        $query = $userId ? GroupsModel::find($userId) : new GroupsModel();
        foreach ($data as $field => $value) {
            $query->{$field} = $value;
        }
        return $query->save() ? $query->group_id : 0;
    }
}